package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LitemallGoodsProductMapper;
import org.linlinjava.litemall.db.domain.LitemallGoodsProduct;
import org.linlinjava.litemall.db.domain.LitemallGoodsProductExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class LitemallProductService {

    @Resource
    private LitemallGoodsProductMapper litemallGoodsProductMapper;

    public List<LitemallGoodsProduct> queryByGid(Integer gid) {
        LitemallGoodsProductExample example = new LitemallGoodsProductExample();
        example.or().andGoodsIdEqualTo(gid).andDeletedEqualTo(false);
        return litemallGoodsProductMapper.selectByExample(example);
    }

    public int deleteByGid(Integer id){
        return litemallGoodsProductMapper.updateById(id);
    }

    public int add(LitemallGoodsProduct product){
        product.setAddTime(LocalDateTime.now());
        product.setUpdateTime(LocalDateTime.now());
        return litemallGoodsProductMapper.insert(product);
    }

    public int update(LitemallGoodsProduct product){
        product.setAddTime(LocalDateTime.now());
        product.setUpdateTime(LocalDateTime.now());
        return litemallGoodsProductMapper.updateByPrimaryKeySelective(product);
    }

}
